<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>求数组交集</title>
  </head>
  <body>
    <script>
      //   [1,2,3] [2,4,2]    结果: [2]   [1,2,3,5] [3,2,5] [2,3,5]   结果: [2,3,5]
      /*
    求数组元素交集的个数
     */
      let arr1 = [1, 2, 3];
      let arr2 = [2, 4, 2];
      let arr3 = [];
      for (let i = 0; i < arr1.length; i++) {
        for (let i = 0; i < arr2.length; i++) {
          if (arr1.indexOf(arr2[i]) !== -1) {
            if (!arr3.includes(arr2[i])) arr3.push(arr2[i]);
          }
        }
      }
      console.log(arr3);
    </script>
  </body>
</html>
